<%@mytestobj= Websitesinf.find_by_iscurrent(true) %>
<h2>Create Article</h2>
<%=javascript_include_tag 'prototype'%>
<div id=subform><input id=tagname name=tagname type=hidden value=''></input></div>
<% form_for :article, 
            :url => {:controller =>'articles1',:action => :create,:images=>params[:cbx]}, 
            :html => { :method => :post } do |f| -%>
  <p>Title:<br /><%= f.text_field :title, :size => 60 %></p>
  <p>Synopsis:<br /><%= f.text_area :synopsis, :rows => 8, :cols => 90 %></p>
  <p>Body:<br /><%= f.text_area :body, :rows => 40, :cols => 90 %></p>
  <p>Image Url:<br /><%= f.text_field :imageurl, :size => 80 %></p>    
  <p>Category:<br />
    <%= f.collection_select :category_id, Category.find(:all,:conditions=>['websitesinf_id = ?',@mytestobj.id]), :id, :name %></p>
  <p>Tag:<br />
  		    <%= f.collection_select :tag_id, Tag.find(:all,:conditions=>['websitesinf_id = ?',@mytestobj.id]), :id, :name %><%= link_to_remote "Add a new tag", 
       :url => {:controller=>"article_tags",:action => "addt"},:method=>:get,:submit => "subform",:condition =>"add_tag()"  %></p>    
  <p>Alias name:<br />

    <%= f.collection_select :user_published_by, Ualia.find(:all), :name, :name %></p>   
    
   <p>Websites to publish:<br />
		 <% options = Websitesinf.find(:all).collect do |c| 
		      [ c.name, c.id ] 
		    end %>
     <%= select_tag 'mymstest[]',options_for_select(options),:multiple => true %></p>      
       
   <% if logged_in_user.has_role?('administrator')%>
  <p>Published? <%= f.check_box :published %></p>
  <%end%>
  <%= submit_tag 'Save' %> or <%= link_to 'cancel', articles_url %>
<% end -%>

<script language="javascript">
	function add_tag()
	{
	  var a=prompt('Please enter a tag name','');
	  if(a)
	  {
	    a=a.strip()
	    if(a.length>0)
	    {
	    	for(i=0;i<$('article_tag_id').length;++i)
	    		if($('article_tag_id').options[i].text==a)
	    		{
		    		$('article_tag_id').value=$('article_tag_id').options[i].value;
	    			return false;
	    		}
	    	$('tagname').value=a;
	    	return true;
	    }
	  }
	  return false;
	}
 function selectInput()
 {
 var someObject = <%= @mytestobj.attributes.to_json %>; 

   for (var i=0;i<document.getElementById("mymstest[]").options.length;i++)
   {
   if (document.getElementById("mymstest[]").options[i].value==someObject.id)
   {document.getElementById("mymstest[]").options[i].selected = true;
   }
   }
 }
  window.load=selectInput();
 </script>